package application;	

import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.geom.AffineTransform;
import java.io.File;
import java.util.Scanner;

import javafx.application.Application;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class BasicTools {
	

	static double[] windowSize =  new double[2];
	static SimpleDoubleProperty scale = new SimpleDoubleProperty();
	static SimpleDoubleProperty volumeValue = new SimpleDoubleProperty();
	
	public static void getStageSettings() {
		File settingsFile = new File("Settings.txt");
		
	    GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
	    AffineTransform tx = gc.getDefaultTransform();
		double uiScaleX = tx.getScaleX();
		double uiScaleY = tx.getScaleY();

		
		try (Scanner settingsScanner = new Scanner(settingsFile)) {
			String windowsSizeString = settingsScanner.nextLine();
			if (windowsSizeString.equals("Large")) {
				windowSize[0] = 1920 / uiScaleX;
				windowSize[1] = 1080 / uiScaleY;
			}
			else if (windowsSizeString.equals("Medium")) {
				windowSize[0] = 1600 / uiScaleX;
				windowSize[1] = 900 / uiScaleY;	
			}
			else if (windowsSizeString.equals("Small")) {
				windowSize[0] = 1280 / uiScaleX;
				windowSize[1] = 720 / uiScaleY;
			}
			
			
			volumeValue.setValue(Double.parseDouble(settingsScanner.nextLine()));
			scale.setValue(BasicTools.windowSize[0] / 1080);
		} catch (Exception e) {
			e.printStackTrace();
		}	
	}	
	
	public static void changeStageSize(Stage primaryStage) {
		getStageSettings();
		primaryStage.setResizable(false);
		primaryStage.setWidth(windowSize[0]);
		primaryStage.setHeight(windowSize[1]);
	}
	
	
	
	
	
	public static void changeScene(Stage primaryStage, Scene scene) {
		getStageSettings();
		primaryStage.setResizable(false);
		primaryStage.setScene(scene);
	}
	
	
	public static void changeSceneExpand(Stage primaryStage, Scene scene) {
		getStageSettings();
		primaryStage.setResizable(false);
		primaryStage.setScene(scene);
		primaryStage.setWidth(primaryStage.getWidth() + 0.0001);
		primaryStage.setHeight(primaryStage.getHeight() + 0.0001);
	}
	
	public static void changeSceneShrink(Stage primaryStage, Scene scene) {
		getStageSettings();
		primaryStage.setResizable(false);
		primaryStage.setScene(scene);
		changeStageSize(primaryStage);
	}
	
	
	public static void launchStage(Application application) {
		try {
			application.start(new Stage());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
